package com.example.administrator.zkdemo.activity;

import android.app.FragmentManager;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.hardware.Camera;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.speech.tts.TextToSpeech;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.MotionEvent;
import android.view.SurfaceView;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.administrator.zkdemo.controller.FaceController;
import com.example.administrator.zkdemo.dao.ZKSignInDao;
import com.example.administrator.zkdemo.db.orm.manager.DataManager;
import com.example.administrator.zkdemo.db.orm.tna.UserInfo;
import com.example.administrator.zkdemo.fragment.ZKPhotoADFragment;
import com.example.administrator.zkdemo.fragment.ZKVideoADFragment;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.orhanobut.logger.Logger;
import com.sensetime.mid.faceapi.model.FaceSearchResult;
import com.zkteco.android.core.sdk.HubProtocolManager;
import com.zkteco.android.db.orm.tna.AttLog;
import com.zkteco.android.db.orm.tna.MeetInfo;
import com.zkteco.android.db.orm.tna.PersonMeet;
import com.zkteco.android.http.ZKBaseCallBean;
import com.zkteco.android.http.ZKDisPatchBean;
import com.zkteco.android.http.ZKDisPatchBean.PayloadBean;
import com.zkteco.android.http.ZKDisPatchBean.PayloadBean.ParamsBean;
import com.zkteco.android.http.ZKRetrofitManage;
import com.zkteco.android.http.ZKRetrofitService;
import com.zkteco.android.http.ZKWeatherBean;
import com.zkteco.android.http.ZKWeatherTokenBean;
import com.zkteco.android.model.ZKADVideoBean;
import com.zkteco.android.model.ZKAttLogInfo;
import com.zkteco.android.receiver.ZKNetBroadcastReceiver;
import com.zkteco.android.receiver.ZKNetBroadcastReceiver.NetEvent;
import com.zkteco.android.receiver.ZKTimeBroadcastReceiver;
import com.zkteco.android.receiver.ZKTimeBroadcastReceiver.TimeEvent;
import com.zkteco.android.utils.ZKCameraTextureView;
import com.zkteco.android.utils.ZKFilePath;
import com.zkteco.android.utils.ZKFileUtils;
import com.zkteco.android.utils.ZKMD5Util;
import com.zkteco.android.utils.ZKNetWork;
import com.zkteco.android.utils.ZKSPUtils;
import com.zkteco.android.utils.ZXingUtils;
import com.zkteco.android.utils.constant.ZKMapData;
import com.zkteco.android.utils.view.ZKToast;
import com.zkteco.android.view.adapter.ZKSignInAdapter;
import com.zkteco.android.view.controller.LiveFaceListener;

import java.io.File;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import butterknife.BindView;
import butterknife.OnClick;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created with Android Studio.
 * 描述: ${DESCRIPTION}
 * Date: 2018/11/20
 * Time: 10:17
 *
 * @author 晏琦云
 * @version ${VERSION}
 */
public class ZKSignInActivity extends ZKBaseActivity
        implements LiveFaceListener {
    private static final String TAG = "ZKSignInActivity";
    private static boolean isFaceSdkInited = false;
    public int MaxAttLogCount = 0;

    @BindView(R.id.fl_ad)
    FrameLayout flAd;

    @BindView(2131296436)
    ImageView iv_qr_code;

    @BindView(2131296460)
    LinearLayout llSign;
    private boolean mADOnOff;
    private long mADStaTime = System.currentTimeMillis();
    private int mADTime;
    private int mActualCount;
    private ZKSignInAdapter mAdapter;
    private ZKRetrofitService mApi;

    @BindView(2131296355)
    ZKCameraTextureView mCameraView;
    private FaceController mController;
    private float mCurPosX;
    private float mCurPosY;
    private ZKSignInDao mDao;
    private List<ZKAttLogInfo> mData = new ArrayList();
    private DataManager mDataManager;
    private int mExpected;
    private Fragment mFragPhotoAd;
    private Fragment mFragVideoAd;
    private Call<ZKBaseCallBean<ZKWeatherTokenBean>> mGetTokenCall;
    private Call<ZKBaseCallBean<ZKWeatherBean>> mGetWeatherCall;
    private Timer mGetWeatherTimer;
    private TimerTask mGetWeatherTimerTask = new TimerTask() {
        public void run() {
            ZKSignInActivity.this.httpGetToken("SN_RK3399_1");
        }
    };
    private HubProtocolManager mHubManager;
    private float mLiveConfidence;
    private int mLoopDeleteLog;
    private MeetInfo mMeetInfo;
    private long mMenuStaTime;
    private boolean mMenuState;

    @BindView(2131296566)
    SurfaceView mOverlapView;
    private boolean mPageState;
    private float mPosX;
    private float mPosY;
    private int mPrivilegeTime;
    private ZKNetBroadcastReceiver mReceiver;
    private int mRepeatSignTime;
    private String mSignInEndTime1;
    private String mSignInEndTime2;
    private String mSignInEndTime3;
    private String mSignInEndTime4;
    private String mSignInStrTime1;
    private String mSignInStrTime2;
    private String mSignInStrTime3;
    private String mSignInStrTime4;
    private boolean mSignInTimeNF1;
    private boolean mSignInTimeNF2;
    private boolean mSignInTimeNF3;
    private boolean mSignInTimeNF4;
    private String mSignInTitle;
    private boolean mSpeakState;
    private TextToSpeech mTextToSpeech;
    private boolean mThreadState;
    private int mThreshold;
    private ZKTimeBroadcastReceiver mTimeReceiver;
    private ProgressDialog progressDialog;

    @BindView(2131296503)
    RelativeLayout rl_sign;

    @BindView(2131296510)
    RecyclerView rv_record;
    private ExecutorService ttsThdPool = Executors.newFixedThreadPool(1);

    @BindView(2131296590)
    TextView tv_actual;

    @BindView(2131296594)
    TextView tv_date;

    @BindView(2131296597)
    TextView tv_expected;

    @BindView(2131296616)
    TextView tv_not;

    @BindView(2131296635)
    TextView tv_title;

    @BindView(2131296639)
    TextView tv_weather;

    @BindView(2131296640)
    ImageView tv_wifi;

    public static void actionStart(Context paramContext) {
        paramContext.startActivity(new Intent(paramContext, ZKSignInActivity.class));
    }

    private void addAttLog(UserInfo paramUserInfo, SimpleDateFormat paramSimpleDateFormat, boolean paramBoolean) {
        monitorenter;
        while (true)
            try {
                Date localDate = new Date();
                if (this.mMeetInfo == null)
                    continue;
                boolean bool = checkMeetingTime(this.mMeetInfo);
                if (!bool)
                    return;
                bool = checkTime(localDate);
                if (!bool)
                    return;
                Object localObject1 = TAG;
                Object localObject2 = new StringBuilder();
                ((StringBuilder) localObject2).append("begin mSpeakState=[");
                ((StringBuilder) localObject2).append(this.mSpeakState);
                ((StringBuilder) localObject2).append("]");
                Logger.i((String) localObject1, new Object[]{((StringBuilder) localObject2).toString()});
                localObject1 = new AttLog();
                ((AttLog) localObject1).setUser_PIN(paramUserInfo.getUser_PIN());
                ((AttLog) localObject1).setVerify_Time(paramSimpleDateFormat.format(localDate));
                ((AttLog) localObject1).setVerify_Type(16);
                ((AttLog) localObject1).setStatus(255);
                try {
                    ((AttLog) localObject1).create();
                    this.mHubManager = new HubProtocolManager(this);
                    localObject2 = this.mHubManager;
                    String str1 = ((AttLog) localObject1).getUser_PIN();
                    Object localObject3 = new StringBuilder();
                    ((StringBuilder) localObject3).append(((AttLog) localObject1).getVerify_Type());
                    ((StringBuilder) localObject3).append("");
                    localObject3 = ((StringBuilder) localObject3).toString();
                    String str2 = ((AttLog) localObject1).getVerify_Time();
                    Object localObject4 = new StringBuilder();
                    ((StringBuilder) localObject4).append(((AttLog) localObject1).getStatus());
                    ((StringBuilder) localObject4).append("");
                    ((HubProtocolManager) localObject2).sendAttLogToPush(str1, (String) localObject3, str2, ((StringBuilder) localObject4).toString());
                    localObject2 = this.mHubManager;
                    str1 = ((AttLog) localObject1).getUser_PIN();
                    localObject3 = new StringBuilder();
                    ((StringBuilder) localObject3).append(((AttLog) localObject1).getVerify_Type());
                    ((StringBuilder) localObject3).append("");
                    localObject3 = ((StringBuilder) localObject3).toString();
                    str2 = ((AttLog) localObject1).getVerify_Time();
                    localObject4 = new StringBuilder();
                    ((StringBuilder) localObject4).append(((AttLog) localObject1).getStatus());
                    ((StringBuilder) localObject4).append("");
                    localObject4 = ((StringBuilder) localObject4).toString();
                    StringBuilder localStringBuilder = new StringBuilder();
                    localStringBuilder.append(((AttLog) localObject1).getWork_Code_ID());
                    localStringBuilder.append("");
                    ((HubProtocolManager) localObject2).sendRealTimeEventForAttLog(str1, (String) localObject3, str2, (String) localObject4, localStringBuilder.toString());
                    this.mHubManager.sendRealTimeEventForVerifyFP(((AttLog) localObject1).getUser_PIN());
                } catch (Exception localException) {
                    localException.printStackTrace();
                }
                if (this.mSpeakState) {
                    this.ttsThdPool.execute(new Runnable(paramUserInfo) {
                        public void run() {
                            int i = ZKSignInActivity.this.mTextToSpeech.speak(this.val$bean.getName(), 1, null);
                            String str = ZKSignInActivity.TAG;
                            StringBuilder localStringBuilder = new StringBuilder();
                            localStringBuilder.append("speak errCode =[");
                            localStringBuilder.append(i);
                            localStringBuilder.append("]");
                            Logger.i(str, new Object[]{localStringBuilder.toString()});
                        }
                    });
                    runOnUiThread(new Runnable(paramBoolean, paramUserInfo, localDate, paramSimpleDateFormat) {
                        public void run() {
                            SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("HH:mm:ss", Locale.getDefault());
                            if (this.val$state) {
                                ZKMapData.putMeetCode(String.valueOf(ZKSignInActivity.this.mMeetInfo.getCode()));
                                if (ZKSignInActivity.this.mDao.getState(ZKSignInActivity.this.mMeetInfo.getCode(), this.val$bean.getUser_PIN())) {
                                    ZKSignInActivity.this.mData.add(0, new ZKAttLogInfo(this.val$bean.getUser_PIN(), this.val$bean.getName(), localSimpleDateFormat.format(this.val$nowData), this.val$bean.getUser_PIN(), true));
                                    ZKMapData.MEET_MAP.put(this.val$bean.getUser_PIN(), this.val$format.format(this.val$nowData));
                                    ZKMapData.ATT_MAP.put(this.val$bean.getUser_PIN(), this.val$format.format(this.val$nowData));
                                } else {
                                    ZKSignInActivity.this.mData.add(0, new ZKAttLogInfo(this.val$bean.getUser_PIN(), this.val$bean.getName(), localSimpleDateFormat.format(this.val$nowData), this.val$bean.getUser_PIN(), false));
                                    ZKMapData.ATT_MAP.put(this.val$bean.getUser_PIN(), this.val$format.format(this.val$nowData));
                                }
                                int i = ZKMapData.MEET_MAP.size();
                                if (i <= 1)
                                    ZKSignInActivity.access$1202(ZKSignInActivity.this, 0);
                                else
                                    ZKSignInActivity.access$1202(ZKSignInActivity.this, i - 1);
                                ZKSignInActivity.this.tv_expected.setText(String.valueOf(ZKSignInActivity.this.mExpected));
                                ZKSignInActivity.this.tv_actual.setText(String.valueOf(ZKSignInActivity.this.mActualCount));
                                ZKSignInActivity.this.tv_not.setText(String.valueOf(ZKSignInActivity.this.mExpected - ZKSignInActivity.this.mActualCount));
                                ZKSignInActivity.this.tv_title.setText(ZKSignInActivity.this.mMeetInfo.getMetName());
                            } else {
                                Logger.d("yfing.wei", new Object[]{"增加考勤记录: "});
                                ZKMapData.ATT_MAP.put(this.val$bean.getUser_PIN(), this.val$format.format(this.val$nowData));
                                ZKSignInActivity.this.mData.add(0, new ZKAttLogInfo(this.val$bean.getUser_PIN(), this.val$bean.getName(), localSimpleDateFormat.format(this.val$nowData), this.val$bean.getUser_PIN(), false));
                                ZKSignInActivity.access$1102(ZKSignInActivity.this, ZKSignInActivity.this.mDao.getUserCount());
                                ZKSignInActivity.access$1202(ZKSignInActivity.this, ZKMapData.getAttSignCount());
                                ZKSignInActivity.this.tv_expected.setText(String.valueOf(ZKSignInActivity.this.mExpected));
                                ZKSignInActivity.this.tv_actual.setText(String.valueOf(ZKSignInActivity.this.mActualCount));
                                ZKSignInActivity.this.tv_not.setText(String.valueOf(ZKSignInActivity.this.mExpected - ZKSignInActivity.this.mActualCount));
                                ZKSignInActivity.this.tv_title.setText(ZKSignInActivity.this.mSignInTitle);
                            }
                            if (ZKSignInActivity.this.mData.size() > 30) {
                                ZKSignInActivity.this.mData.remove(ZKSignInActivity.this.mData.size() - 1);
                                ZKSignInActivity.this.mAdapter.notifyItemRemoved(ZKSignInActivity.this.mData.size() - 1);
                            }
                            ZKSignInActivity.this.mAdapter.notifyItemInserted(0);
                            ZKSignInActivity.this.rv_record.scrollToPosition(0);
                        }
                    });
                    return;
                }
            } finally {
                monitorexit;
            }
    }

    private boolean checkMeetingTime(MeetInfo paramMeetInfo) {
        if (paramMeetInfo != null) {
            String str1 = paramMeetInfo.getMetLatSignTm();
            String str2 = paramMeetInfo.getEarRetTm();
            if ((TextUtils.isEmpty(str1)) && (TextUtils.isEmpty(str2)))
                return isMeetingTime(paramMeetInfo);
            if ((isInCheckInTime(paramMeetInfo)) || (isInCheckOutTime(paramMeetInfo)))
                return true;
        }
        return false;
    }

    private boolean checkTime(Date paramDate) {
        Object localObject1 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.getDefault());
        String str = new SimpleDateFormat("yyyy-MM-dd'T'", Locale.getDefault()).format(paramDate);
        while (true) {
            try {
                Object localObject2 = new StringBuilder();
                ((StringBuilder) localObject2).append(str);
                ((StringBuilder) localObject2).append(this.mSignInStrTime1);
                ((StringBuilder) localObject2).append(":00");
                localObject2 = ((SimpleDateFormat) localObject1).parse(((StringBuilder) localObject2).toString());
                Object localObject3 = new StringBuilder();
                ((StringBuilder) localObject3).append(str);
                ((StringBuilder) localObject3).append(this.mSignInEndTime1);
                ((StringBuilder) localObject3).append(":59");
                localObject3 = ((SimpleDateFormat) localObject1).parse(((StringBuilder) localObject3).toString());
                Object localObject4 = new StringBuilder();
                ((StringBuilder) localObject4).append(str);
                ((StringBuilder) localObject4).append(this.mSignInStrTime2);
                ((StringBuilder) localObject4).append(":00");
                localObject4 = ((SimpleDateFormat) localObject1).parse(((StringBuilder) localObject4).toString());
                Object localObject5 = new StringBuilder();
                ((StringBuilder) localObject5).append(str);
                ((StringBuilder) localObject5).append(this.mSignInEndTime2);
                ((StringBuilder) localObject5).append(":59");
                localObject5 = ((SimpleDateFormat) localObject1).parse(((StringBuilder) localObject5).toString());
                Object localObject6 = new StringBuilder();
                ((StringBuilder) localObject6).append(str);
                ((StringBuilder) localObject6).append(this.mSignInStrTime3);
                ((StringBuilder) localObject6).append(":00");
                localObject6 = ((SimpleDateFormat) localObject1).parse(((StringBuilder) localObject6).toString());
                Object localObject7 = new StringBuilder();
                ((StringBuilder) localObject7).append(str);
                ((StringBuilder) localObject7).append(this.mSignInEndTime3);
                ((StringBuilder) localObject7).append(":59");
                localObject7 = ((SimpleDateFormat) localObject1).parse(((StringBuilder) localObject7).toString());
                Object localObject8 = new StringBuilder();
                ((StringBuilder) localObject8).append(str);
                ((StringBuilder) localObject8).append(this.mSignInStrTime4);
                ((StringBuilder) localObject8).append(":00");
                localObject8 = ((SimpleDateFormat) localObject1).parse(((StringBuilder) localObject8).toString());
                StringBuilder localStringBuilder = new StringBuilder();
                localStringBuilder.append(str);
                localStringBuilder.append(this.mSignInEndTime4);
                localStringBuilder.append(":59");
                localObject1 = ((SimpleDateFormat) localObject1).parse(localStringBuilder.toString());
                boolean bool1 = this.mSignInTimeNF1;
                boolean bool2 = true;
                if ((bool1) && (paramDate.getTime() >= ((Date) localObject2).getTime()) && (paramDate.getTime() <= ((Date) localObject3).getTime())) {
                    i = 1;
                    if ((!this.mSignInTimeNF2) || (paramDate.getTime() < ((Date) localObject4).getTime()) || (paramDate.getTime() > ((Date) localObject5).getTime()))
                        break label640;
                    j = 1;
                    if ((!this.mSignInTimeNF3) || (paramDate.getTime() < ((Date) localObject6).getTime()) || (paramDate.getTime() > ((Date) localObject7).getTime()))
                        break label645;
                    k = 1;
                    if ((!this.mSignInTimeNF4) || (paramDate.getTime() < ((Date) localObject8).getTime()))
                        continue;
                    long l1 = paramDate.getTime();
                    long l2 = ((Date) localObject1).getTime();
                    if (l1 > l2)
                        continue;
                    int m = 1;
                    continue;
                    m = 0;
                    bool1 = bool2;
                    if (i != 0)
                        continue;
                    bool1 = bool2;
                    if (j != 0)
                        continue;
                    bool1 = bool2;
                    if (k != 0)
                        continue;
                    if (m != 0)
                        return true;
                    bool1 = false;
                    return bool1;
                }
            } catch (ParseException paramDate) {
                paramDate.printStackTrace();
                return false;
            }
            int i = 0;
            continue;
            label640:
            int j = 0;
            continue;
            label645:
            int k = 0;
        }
    }

    private Bitmap decodeFromFile(String paramString) {
        if (!new File(paramString).exists())
            return null;
        BitmapFactory.Options localOptions = new BitmapFactory.Options();
        localOptions.inMutable = true;
        localOptions.inSampleSize = 1;
        localOptions.inPurgeable = true;
        localOptions.inInputShareable = true;
        return BitmapFactory.decodeFile(paramString, localOptions);
    }

    private List<String> getADVideoData() {
        ArrayList localArrayList = new ArrayList();
        Object localObject2 = new ArrayList();
        String str = (String) ZKSPUtils.getParam(this, "AD_VIDEO", "");
        Object localObject1 = localObject2;
        if (str != null) {
            localObject1 = localObject2;
            if (!str.equals(""))
                localObject1 = (List) new Gson().fromJson(str, new TypeToken() {
                }
                        .getType());
        }
        localObject2 = new File(ZKFilePath.AD_VIDEO_PATH).listFiles();
        int j = localObject2.length;
        int i = 0;
        while (i < j) {
            str = localObject2[i];
            if ((!str.isDirectory()) && (ZKFileUtils.checkVideoSuffix(str.getName())) && (((List) localObject1).size() > 0)) {
                Iterator localIterator = ((List) localObject1).iterator();
                while (localIterator.hasNext()) {
                    if (!((ZKADVideoBean) localIterator.next()).getName().equals(str.getName()))
                        continue;
                    localArrayList.add(str.getAbsolutePath());
                }
            }
            i += 1;
        }
        return (List<String>) (List<String>) localArrayList;
    }

    private void httpDispatch(ZKDisPatchBean paramZKDisPatchBean) {
        this.mGetWeatherCall = this.mApi.dispatch(paramZKDisPatchBean);
        this.mGetWeatherCall.enqueue(new Callback() {
            public void onFailure(Call<ZKBaseCallBean<ZKWeatherBean>> paramCall, Throwable paramThrowable) {
                Logger.d("httpDispatch onFailure ");
            }

            public void onResponse(Call<ZKBaseCallBean<ZKWeatherBean>> paramCall, Response<ZKBaseCallBean<ZKWeatherBean>> paramResponse) {
                if (((ZKBaseCallBean) paramResponse.body()).getCode().equals("00000000")) {
                    paramCall = ((ZKWeatherBean) ((ZKBaseCallBean) paramResponse.body()).getPayload()).getResults();
                    paramResponse = ZKSignInActivity.this.tv_weather;
                    StringBuilder localStringBuilder = new StringBuilder();
                    localStringBuilder.append(paramCall.getReportDate());
                    localStringBuilder.append("　");
                    localStringBuilder.append(paramCall.getWeek());
                    paramResponse.setText(localStringBuilder.toString());
                    paramResponse = ZKSignInActivity.this.tv_date;
                    localStringBuilder = new StringBuilder();
                    localStringBuilder.append(paramCall.getSkTemperature());
                    localStringBuilder.append("°C　");
                    localStringBuilder.append(paramCall.getWeather());
                    paramResponse.setText(localStringBuilder.toString());
                    Logger.d("httpDispatch Update");
                }
            }
        });
    }

    private void httpGetToken(String paramString) {
        this.mGetTokenCall = this.mApi.getToken(paramString, ZKMD5Util.getKey(paramString));
        this.mGetTokenCall.enqueue(new Callback() {
            public void onFailure(Call<ZKBaseCallBean<ZKWeatherTokenBean>> paramCall, Throwable paramThrowable) {
                Logger.i("httpGetToken onFailure ", new Object[0]);
            }

            public void onResponse(Call<ZKBaseCallBean<ZKWeatherTokenBean>> paramCall, Response<ZKBaseCallBean<ZKWeatherTokenBean>> paramResponse) {
                if (paramResponse.body() != null) {
                    if (((ZKBaseCallBean) paramResponse.body()).getCode().equals("00000000")) {
                        paramCall = ((ZKWeatherTokenBean) ((ZKBaseCallBean) paramResponse.body()).getPayload()).getResults().getToken();
                        paramResponse = new ZKDisPatchBean();
                        paramResponse.setSid("device.apiv1.weather.getWeatherByToken");
                        paramResponse.setPayload(new ZKDisPatchBean.PayloadBean(new ZKDisPatchBean.PayloadBean.ParamsBean("SN_RK3399_1", paramCall)));
                        ZKSignInActivity.this.httpDispatch(paramResponse);
                        return;
                    }
                    paramCall = new StringBuilder();
                    paramCall.append("httpGetToken onResponse :  ");
                    paramCall.append(((ZKBaseCallBean) paramResponse.body()).toString());
                    Logger.d(paramCall.toString());
                    return;
                }
                Logger.d("httpGetToken onResponse : is null ");
            }
        });
    }

    private void initData() {
        this.mDataManager = new DataManager();
        this.mDataManager.open(getApplicationContext());
        this.mDao = new ZKSignInDao(this.mDataManager);
        reloadSettings();
        reloadFaceController();
        this.mTextToSpeech = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
            public void onInit(int paramInt) {
            }
        });
        saveIpOption(this.mDataManager);
    }

    private void initHttp() {
        this.mApi = ZKRetrofitManage.getInstance().getApi();
    }

    private void initReceiver() {
        this.mReceiver = new ZKNetBroadcastReceiver();
        this.mReceiver.setEvent(new ZKNetBroadcastReceiver.NetEvent() {
            public void onNetChange(boolean paramBoolean) {
                if (paramBoolean) {
                    ZKSignInActivity.this.tv_wifi.setVisibility(8);
                    return;
                }
                ZKSignInActivity.this.tv_wifi.setVisibility(0);
            }
        });
        this.mTimeReceiver = new ZKTimeBroadcastReceiver();
        this.mTimeReceiver.setEvent(new ZKTimeBroadcastReceiver.TimeEvent() {
            public void onTimeChange() {
                ZKSignInActivity.this.setPageType();
            }
        });
        IntentFilter localIntentFilter = new IntentFilter();
        localIntentFilter.addAction("android.net.conn.CONNECTIVITY_CHANGE");
        registerReceiver(this.mReceiver, localIntentFilter);
        localIntentFilter = new IntentFilter();
        localIntentFilter.addAction("android.intent.action.TIME_TICK");
        registerReceiver(this.mTimeReceiver, localIntentFilter);
    }

    private void initView() {
        Logger.d("yfing.weiinitView:  初始化。。。。");
        setGestureListener(this.rl_sign);
        this.iv_qr_code.setImageBitmap(ZXingUtils.createQRImage((String) ZKSPUtils.getParam(this, "QR_ADDRESS", "http://cn.zkteco.com/"), 300, 300));
        this.rv_record.setLayoutManager(new GridLayoutManager(this, 3));
        this.rv_record.setItemAnimator(new DefaultItemAnimator());
        this.mAdapter = new ZKSignInAdapter(this, this.mData);
        this.rv_record.setAdapter(this.mAdapter);
        this.mOverlapView.setZOrderOnTop(true);
        this.mOverlapView.getHolder().setFormat(-3);
        this.mOverlapView.setLayoutParams(this.mCameraView.getLayoutParams());
        this.mCameraView.setPreviewCallback(new Camera.PreviewCallback() {
            public void onPreviewFrame(byte[] paramArrayOfByte, Camera paramCamera) {
                ZKSignInActivity.this.mCameraView.addCallbackBuffer();
                if (ZKSignInActivity.this.mController != null) {
                    if (ZKSignInActivity.this.mController.isPaused)
                        return;
                    if ((ZKSignInActivity.this.mController.mNv21 == null) || (paramArrayOfByte.length != ZKSignInActivity.this.mController.mNv21.length)) {
                        ZKSignInActivity.this.mController.mNv21 = new byte[paramArrayOfByte.length];
                        ZKSignInActivity.this.mController.mFaceData = new byte[paramArrayOfByte.length];
                        ZKSignInActivity.this.mController.mPaint.setStrokeWidth(3.0F);
                    }
                    if (!ZKSignInActivity.this.mController.mNv21GetReady) {
                        System.arraycopy(paramArrayOfByte, 0, ZKSignInActivity.this.mController.mNv21, 0, paramArrayOfByte.length);
                        ZKSignInActivity.this.mController.mNv21GetReady = true;
                    }
                    return;
                }
            }
        });
        this.mCameraView.startPreview();
        startThread();
        setPageType();
    }

    // ERROR //
    private void insertBioTemplate2DB(DataManager paramDataManager) {
        // Byte code:
        //   0: invokestatic 855	com/sensetime/mid/faceapi/FaceSearch:deleteAll	()V
        //   3: iconst_0
        //   4: istore_2
        //   5: new 348	java/lang/StringBuilder
        //   8: dup
        //   9: invokespecial 349	java/lang/StringBuilder:<init>	()V
        //   12: astore 6
        //   14: aload 6
        //   16: ldc_w 857
        //   19: invokevirtual 355	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
        //   22: pop
        //   23: aload 6
        //   25: iload_2
        //   26: bipush 100
        //   28: imul
        //   29: invokevirtual 418	java/lang/StringBuilder:append	(I)Ljava/lang/StringBuilder;
        //   32: pop
        //   33: aload 6
        //   35: ldc_w 859
        //   38: invokevirtual 355	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
        //   41: pop
        //   42: aload 6
        //   44: bipush 100
        //   46: invokevirtual 418	java/lang/StringBuilder:append	(I)Ljava/lang/StringBuilder;
        //   49: pop
        //   50: aload 6
        //   52: ldc_w 861
        //   55: invokevirtual 355	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
        //   58: pop
        //   59: aload 6
        //   61: invokevirtual 367	java/lang/StringBuilder:toString	()Ljava/lang/String;
        //   64: astore 7
        //   66: aconst_null
        //   67: astore 8
        //   69: aconst_null
        //   70: astore 6
        //   72: aload_1
        //   73: aload 7
        //   75: invokevirtual 865	com/zkteco/android/db/orm/manager/DataManager:queryBySql	(Ljava/lang/String;)Landroid/database/Cursor;
        //   78: astore 7
        //   80: aload 7
        //   82: invokeinterface 870 1 0
        //   87: ifeq +60 -> 147
        //   90: aload 7
        //   92: aload 7
        //   94: ldc_w 872
        //   97: invokeinterface 875 2 0
        //   102: invokeinterface 879 2 0
        //   107: lstore 4
        //   109: aload 7
        //   111: aload 7
        //   113: ldc_w 881
        //   116: invokeinterface 875 2 0
        //   121: invokeinterface 885 2 0
        //   126: astore 6
        //   128: lload 4
        //   130: l2i
        //   131: aload 6
        //   133: invokestatic 889	com/sensetime/mid/faceapi/FaceSearch:insert	(I[B)I
        //   136: pop
        //   137: aload 7
        //   139: invokeinterface 892 1 0
        //   144: ifne -54 -> 90
        //   147: aload 7
        //   149: invokeinterface 895 1 0
        //   154: istore_3
        //   155: iload_3
        //   156: ifne +16 -> 172
        //   159: aload 7
        //   161: ifnull +114 -> 275
        //   164: aload 7
        //   166: invokeinterface 898 1 0
        //   171: return
        //   172: iload_2
        //   173: iconst_1
        //   174: iadd
        //   175: istore_3
        //   176: new 348	java/lang/StringBuilder
        //   179: dup
        //   180: invokespecial 349	java/lang/StringBuilder:<init>	()V
        //   183: astore 6
        //   185: aload 6
        //   187: ldc_w 900
        //   190: invokevirtual 355	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
        //   193: pop
        //   194: aload 6
        //   196: iload_3
        //   197: invokevirtual 418	java/lang/StringBuilder:append	(I)Ljava/lang/StringBuilder;
        //   200: pop
        //   201: aload 6
        //   203: invokevirtual 367	java/lang/StringBuilder:toString	()Ljava/lang/String;
        //   206: invokestatic 756	com/orhanobut/logger/Logger:d	(Ljava/lang/Object;)V
        //   209: iload_3
        //   210: istore_2
        //   211: aload 7
        //   213: ifnull -208 -> 5
        //   216: aload 7
        //   218: invokeinterface 898 1 0
        //   223: iload_3
        //   224: istore_2
        //   225: goto -220 -> 5
        //   228: astore_1
        //   229: goto +47 -> 276
        //   232: astore 6
        //   234: aload 7
        //   236: astore_1
        //   237: aload 6
        //   239: astore 7
        //   241: goto +16 -> 257
        //   244: astore_1
        //   245: aload 6
        //   247: astore 7
        //   249: goto +27 -> 276
        //   252: astore 7
        //   254: aload 8
        //   256: astore_1
        //   257: aload_1
        //   258: astore 6
        //   260: aload 7
        //   262: invokevirtual 444	java/lang/Exception:printStackTrace	()V
        //   265: aload_1
        //   266: ifnull +9 -> 275
        //   269: aload_1
        //   270: invokeinterface 898 1 0
        //   275: return
        //   276: aload 7
        //   278: ifnull +10 -> 288
        //   281: aload 7
        //   283: invokeinterface 898 1 0
        //   288: aload_1
        //   289: athrow
        //
        // Exception table:
        //   from	to	target	type
        //   80	90	228	finally
        //   90	147	228	finally
        //   147	155	228	finally
        //   176	209	228	finally
        //   80	90	232	java/lang/Exception
        //   90	147	232	java/lang/Exception
        //   147	155	232	java/lang/Exception
        //   176	209	232	java/lang/Exception
        //   72	80	244	finally
        //   260	265	244	finally
        //   72	80	252	java/lang/Exception
    }

    private boolean isInCheckInTime(MeetInfo paramMeetInfo) {
        if ((!TextUtils.isEmpty(paramMeetInfo.getMetLatSignTm())) && (!TextUtils.isEmpty(paramMeetInfo.getMetStarSignTm()))) {
            Date localDate1 = new Date();
            SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.getDefault());
            try {
                Date localDate2 = localSimpleDateFormat.parse(paramMeetInfo.getMetStarSignTm());
                paramMeetInfo = localSimpleDateFormat.parse(paramMeetInfo.getMetLatSignTm());
                if (localDate1.getTime() >= localDate2.getTime()) {
                    long l1 = localDate1.getTime();
                    long l2 = paramMeetInfo.getTime();
                    if (l1 <= l2)
                        return true;
                }
            } catch (ParseException paramMeetInfo) {
                paramMeetInfo.printStackTrace();
            }
        }
        return false;
    }

    private boolean isInCheckOutTime(MeetInfo paramMeetInfo) {
        if ((!TextUtils.isEmpty(paramMeetInfo.getEarRetTm())) && (!TextUtils.isEmpty(paramMeetInfo.getEarRetTm()))) {
            Date localDate1 = new Date();
            SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.getDefault());
            try {
                Date localDate2 = localSimpleDateFormat.parse(paramMeetInfo.getEarRetTm());
                paramMeetInfo = localSimpleDateFormat.parse(paramMeetInfo.getEarRetTm());
                if (localDate1.getTime() >= localDate2.getTime()) {
                    long l1 = localDate1.getTime();
                    long l2 = paramMeetInfo.getTime();
                    if (l1 <= l2)
                        return true;
                }
            } catch (ParseException paramMeetInfo) {
                paramMeetInfo.printStackTrace();
            }
        }
        return false;
    }

    private boolean isMeetingTime(MeetInfo paramMeetInfo) {
        if (paramMeetInfo != null) {
            Object localObject1 = paramMeetInfo.getMetStarSignTm();
            Object localObject2 = paramMeetInfo.getLatRetTm();
            if ((!TextUtils.isEmpty((CharSequence) localObject1)) && (!TextUtils.isEmpty((CharSequence) localObject2))) {
                localObject1 = new Date();
                SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.getDefault());
                try {
                    localObject2 = localSimpleDateFormat.parse(paramMeetInfo.getMetStarSignTm());
                    paramMeetInfo = localSimpleDateFormat.parse(paramMeetInfo.getLatRetTm());
                    if (((Date) localObject1).getTime() >= ((Date) localObject2).getTime()) {
                        long l1 = ((Date) localObject1).getTime();
                        long l2 = paramMeetInfo.getTime();
                        if (l1 <= l2)
                            return true;
                    }
                } catch (ParseException paramMeetInfo) {
                    paramMeetInfo.printStackTrace();
                }
            }
        }
        return false;
    }

    private void reloadBioData() {
        insertBioTemplate2DB(this.mDataManager);
    }

    /**
     * 初始化人脸识别
     */
    private void reloadFaceController() {
        this.mController = FaceController.getInstance();
        this.progressDialog = new ProgressDialog(this);
        if (!isFaceSdkInited) {
            this.progressDialog.setTitle(getString(2131624089));
            this.progressDialog.setCancelable(false);
            this.mController.setLiveFaceListener(this);
            this.mController.isPaused = false;
            this.mController.bindOverView(this.mOverlapView);
            this.mController.bindCameraView(this.mCameraView);
            this.mController.init(getApplicationContext());
            isFaceSdkInited = true;
            new Thread(new Runnable() {
                public void run() {
                    ZKSignInActivity.this.runOnUiThread(new Runnable() {
                        public void run() {
                            ZKSignInActivity.this.progressDialog.show();
                        }
                    });
                }
            }).start();
        } else {
            this.mController.setLiveFaceListener(this);
            this.mController.isPaused = false;
            this.mController.bindOverView(this.mOverlapView);
            this.mController.bindCameraView(this.mCameraView);
            this.mController.isPaused = false;
            this.mController.start();
            new Thread(new Runnable() {
                public void run() {
                    ZKSignInActivity.this.runOnUiThread(new Runnable() {
                        public void run() {
                            ZKSignInActivity.this.progressDialog.show();
                        }
                    });
                    ZKSignInActivity.this.reloadBioData();
                    ZKSignInActivity.this.runOnUiThread(new Runnable() {
                        public void run() {
                            ZKSignInActivity.this.progressDialog.dismiss();
                        }
                    });
                }
            }).start();
        }
        this.mController.setThreshold(this.mThreshold);
        this.mController.setLiveConfidence(this.mLiveConfidence);
    }

    /**
     * 装载配置变量
     */
    private void reloadSettings() {
        this.mThreshold = ((Integer) ZKSPUtils.getParam(this, "THRESHOLD", Integer.valueOf(83))).intValue();
        this.mSignInTitle = ((String) ZKSPUtils.getParam(this, "SIGN_IN_TITLE", getString(2131624170)));
        this.mADOnOff = ((Boolean) ZKSPUtils.getParam(this, "AD_ON_OFF", Boolean.valueOf(false))).booleanValue();
        this.mADTime = ((Integer) ZKSPUtils.getParam(this, "AD_NO_FACE_TIME", Integer.valueOf(10))).intValue();
        this.mPrivilegeTime = ((Integer) ZKSPUtils.getParam(this, "PRIVILEGE_TIME", Integer.valueOf(5))).intValue();
        this.mSpeakState = ((Boolean) ZKSPUtils.getParam(this, "SPEAK_STATE", Boolean.valueOf(false))).booleanValue();
        this.mRepeatSignTime = ((Integer) ZKSPUtils.getParam(this, "REPEAT_SIGN_TIME", Integer.valueOf(0))).intValue();
        this.mLoopDeleteLog = ((Integer) ZKSPUtils.getParam(this, "LOOP_DELETE_LOG", Integer.valueOf(10))).intValue();
        this.mSignInStrTime1 = ((String) ZKSPUtils.getParam(this, "SIGN_IN_STR_TIME_1", "00:00"));
        this.mSignInEndTime1 = ((String) ZKSPUtils.getParam(this, "SIGN_IN_END_TIME_1", "23:59"));
        this.mSignInTimeNF1 = ((Boolean) ZKSPUtils.getParam(this, "SIGN_IN_TIME_NF_1", Boolean.valueOf(true))).booleanValue();
        this.mSignInStrTime2 = ((String) ZKSPUtils.getParam(this, "SIGN_IN_STR_TIME_2", "00:00"));
        this.mSignInEndTime2 = ((String) ZKSPUtils.getParam(this, "SIGN_IN_END_TIME_2", "23:59"));
        this.mSignInTimeNF2 = ((Boolean) ZKSPUtils.getParam(this, "SIGN_IN_TIME_NF_2", Boolean.valueOf(false))).booleanValue();
        this.mSignInStrTime3 = ((String) ZKSPUtils.getParam(this, "SIGN_IN_STR_TIME_3", "00:00"));
        this.mSignInEndTime3 = ((String) ZKSPUtils.getParam(this, "SIGN_IN_END_TIME_3", "23:59"));
        this.mSignInTimeNF3 = ((Boolean) ZKSPUtils.getParam(this, "SIGN_IN_TIME_NF_3", Boolean.valueOf(false))).booleanValue();
        this.mSignInStrTime4 = ((String) ZKSPUtils.getParam(this, "SIGN_IN_STR_TIME_4", "00:00"));
        this.mSignInEndTime4 = ((String) ZKSPUtils.getParam(this, "SIGN_IN_END_TIME_4", "23:59"));
        this.mSignInTimeNF4 = ((Boolean) ZKSPUtils.getParam(this, "SIGN_IN_TIME_NF_4", Boolean.valueOf(false))).booleanValue();
        this.mLiveConfidence = ((Float) ZKSPUtils.getParam(this, "LIVE_CONFIDENCE", Float.valueOf(0.8F))).floatValue();
        this.MaxAttLogCount = (this.mDataManager.getIntOption("~MaxAttLogCount", 0) * 10000);
    }

    private void saveIpOption(DataManager paramDataManager) {
        String str2 = ZKNetWork.getWifiIp(this);
        String str1 = str2;
        if (TextUtils.isEmpty(str2))
            str1 = ZKNetWork.getEthIp();
        if (!TextUtils.isEmpty(str1))
            paramDataManager.setStrOption("IPAddress", str1);
    }

    public static Bitmap scaledBitmap(Bitmap paramBitmap) {
        int i = paramBitmap.getWidth();
        int k = paramBitmap.getHeight();
        int j = 640;
        if (i > k) {
            j = k * 640 / i;
            i = 640;
        } else {
            i = i * 640 / k;
        }
        return Bitmap.createScaledBitmap(paramBitmap, i, j, true);
    }

    private void scheduleGetWeather() {
        this.mGetWeatherTimer = new Timer();
        this.mGetWeatherTimer.schedule(this.mGetWeatherTimerTask, 0L, 3600000L);
    }

    /**
     * 设置手势监听器
     *
     * @param paramView
     */
    private void setGestureListener(View paramView) {
        paramView.setOnTouchListener(new View.OnTouchListener() {
            public boolean onTouch(View paramView, MotionEvent paramMotionEvent) {
                switch (paramMotionEvent.getAction()) {
                    default:
                        break;
                    case 2:
                        ZKSignInActivity.access$2402(ZKSignInActivity.this, paramMotionEvent.getX());
                        ZKSignInActivity.access$2502(ZKSignInActivity.this, paramMotionEvent.getY());
                        break;
                    case 1:
                        if ((ZKSignInActivity.this.mCurPosX - ZKSignInActivity.this.mPosX >= 0.0F) || (Math.abs(ZKSignInActivity.this.mCurPosX - ZKSignInActivity.this.mPosX) <= 25.0F) || (ZKSignInActivity.this.mPosX <= 1050.0F))
                            break;
                        if ((ZKSignInActivity.this.mADOnOff) && (ZKSignInActivity.this.mFragPhotoAd == null) && (ZKSignInActivity.this.mFragVideoAd == null))
                            ZKSignInActivity.this.showAD();
                        paramView = new StringBuilder();
                        paramView.append("滑动了，mPosX = ");
                        paramView.append(ZKSignInActivity.this.mPosX);
                        paramView.append(" mPosY = ");
                        paramView.append(ZKSignInActivity.this.mPosY);
                        paramView.append(" mCurPosX = ");
                        paramView.append(ZKSignInActivity.this.mCurPosX);
                        paramView.append(" mCurPosY = ");
                        paramView.append(ZKSignInActivity.this.mCurPosY);
                        Logger.d(paramView.toString());
                        break;
                    case 0:
                        ZKSignInActivity.access$2202(ZKSignInActivity.this, paramMotionEvent.getX());
                        ZKSignInActivity.access$2302(ZKSignInActivity.this, paramMotionEvent.getY());
                }
                return true;
            }
        });
    }

    private void setPageType() {
        String str = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.getDefault()).format(new Date());
        while (true) {
            try {
                this.mMeetInfo = ((MeetInfo) new MeetInfo().getQueryBuilder().where().le("MetStarSignTm", str).and().ge("LatRetTm", str).queryForFirst());
                if (this.mMeetInfo == null)
                    break label222;
                bool = true;
                this.mPageState = bool;
            } catch (SQLException localSQLException1) {
                localSQLException1.printStackTrace();
            }
            if (this.mPageState)
                try {
                    ZKMapData.putMeetCode(String.valueOf(this.mMeetInfo.getCode()));
                    this.mExpected = (int) new PersonMeet().getQueryBuilder().where().eq("Code", this.mMeetInfo.getCode()).countOf();
                    int i = ZKMapData.MEET_MAP.size();
                    if (i <= 1)
                        this.mActualCount = 0;
                    else
                        this.mActualCount = (i - 1);
                    runOnUiThread(new Runnable() {
                        public void run() {
                            ZKSignInActivity.this.tv_expected.setText(String.valueOf(ZKSignInActivity.this.mExpected));
                            ZKSignInActivity.this.tv_actual.setText(String.valueOf(ZKSignInActivity.this.mActualCount));
                            ZKSignInActivity.this.tv_not.setText(String.valueOf(ZKSignInActivity.this.mExpected - ZKSignInActivity.this.mActualCount));
                            ZKSignInActivity.this.tv_title.setText(ZKSignInActivity.this.mMeetInfo.getMetName());
                        }
                    });
                    return;
                } catch (SQLException localSQLException2) {
                    localSQLException2.printStackTrace();
                    return;
                }
            this.mActualCount = ZKMapData.getAttSignCount();
            this.mExpected = this.mDao.getUserCount();
            runOnUiThread(new Runnable() {
                public void run() {
                    ZKSignInActivity.this.tv_expected.setText(String.valueOf(ZKSignInActivity.this.mExpected));
                    ZKSignInActivity.this.tv_actual.setText(String.valueOf(ZKSignInActivity.this.mActualCount));
                    ZKSignInActivity.this.tv_not.setText(String.valueOf(ZKSignInActivity.this.mExpected - ZKSignInActivity.this.mActualCount));
                    ZKSignInActivity.this.tv_title.setText(ZKSignInActivity.this.mSignInTitle);
                }
            });
            return;
            boolean bool = false;
        }
    }

    private void showAD() {
        FragmentManager localFragmentManager = getFragmentManager();
        ArrayList localArrayList = new ArrayList();
        String str = (String) ZKSPUtils.getParam(getApplicationContext(), "AD_PHOTO", "");
        Object localObject = localArrayList;
        if (str != null) {
            localObject = localArrayList;
            if (!str.equals(""))
                localObject = (List) new Gson().fromJson(str, new TypeToken() {
                }
                        .getType());
        }
        // 如果AD_TYPE值为1，显示Banner Fragment
        if (((Integer) ZKSPUtils.getParam(this, "AD_TYPE", Integer.valueOf(1))).intValue() == 1) {
            if ((localObject != null) && (!((List) localObject).isEmpty())) {
                localObject = localFragmentManager.beginTransaction();
                this.mFragPhotoAd = new ZKPhotoADFragment();
                ((FragmentTransaction) localObject).add(2131296390, this.mFragPhotoAd, ZKPhotoADFragment.TAG);
                ((FragmentTransaction) localObject).commitAllowingStateLoss();
                this.flAd.setVisibility(0);
                this.llSign.setVisibility(8);
                return;
            }
        } else {
            // 否则显示视频播放界面Fragment
            localObject = getADVideoData();
            if ((localObject != null) && (((List) localObject).size() > 0)) {
                localObject = localFragmentManager.beginTransaction();
                this.mFragVideoAd = new ZKVideoADFragment();
                ((FragmentTransaction) localObject).add(2131296390, this.mFragVideoAd, ZKVideoADFragment.TAG);
                ((FragmentTransaction) localObject).commitAllowingStateLoss();
                this.flAd.setVisibility(0);
                this.llSign.setVisibility(8);
            }
        }
    }

    private void startThread() {
        this.mThreadState = false;
        new TimerRun().start();
    }

    private void stopScheduleGetWeather() {
        if ((this.mGetWeatherTimer != null) && (this.mGetWeatherTimerTask != null))
            this.mGetWeatherTimer.cancel();
    }

    // 关闭Fragment
    public void closeAD(Fragment paramFragment) {
        this.mADStaTime = System.currentTimeMillis();
        FragmentTransaction localFragmentTransaction = getSupportFragmentManager().beginTransaction();
        localFragmentTransaction.remove(paramFragment);
        localFragmentTransaction.commitAllowingStateLoss();
        if (paramFragment == this.mFragPhotoAd)
            this.mFragPhotoAd = null;
        else if (paramFragment == this.mFragVideoAd)
            this.mFragVideoAd = null;
        this.llSign.setVisibility(0);
        this.flAd.setVisibility(8);
    }

    protected void onCreate(Bundle paramBundle) {
        super.onCreate(paramBundle);
        initLayout(R.layout.activity_sign_in);
        initData();
        initView();
        initHttp();
        initReceiver();
        scheduleGetWeather();
    }

    protected void onDestroy() {
        this.mController.stop();
        super.onDestroy();
        try {
            this.mGetTokenCall.cancel();
            this.mGetWeatherCall.cancel();
        } catch (Exception localException) {
            localException.printStackTrace();
        }
        if (this.mTextToSpeech != null)
            this.mTextToSpeech.shutdown();
        this.mController.isPaused = true;
        if (ZKCameraTextureView.isPreviewing)
            this.mCameraView.stopPreview();
        Logger.d("Worker ThreadWorker Thread shutdown");
        this.mThreadState = true;
        if (this.mReceiver != null)
            unregisterReceiver(this.mReceiver);
        if (this.mTimeReceiver != null)
            unregisterReceiver(this.mTimeReceiver);
        this.mFragVideoAd = null;
        this.mFragPhotoAd = null;
        stopScheduleGetWeather();
    }

    /**
     * 识别出人脸之后的回调
     *
     * @param paramFaceSearchResult
     */
    public void onFaceRecognized(FaceSearchResult paramFaceSearchResult) {
        UserInfo localUserInfo;
        try {
            localUserInfo = (UserInfo) new UserInfo().queryForId(Long.valueOf(paramFaceSearchResult.userID));
        } catch (SQLException e) {
            e.printStackTrace();
            localUserInfo = null;
        }
        if (localUserInfo == null)
            return;
        if (this.mMenuState) {
            // 如果识别到该用户为管理员，进入到设置页面ZKSettingActivity
            if (this.mDao.query14User() > 0) {
                if (localUserInfo.getPrivilege() == 14) {
                    this.mMenuState = false;
                    Logger.d("yfing.wei", new Object[]{"进入菜单界面: "});
                    Logger.d("yfing.wei", new Object[]{"mCameraView stopPreview: "});
                    runOnUiThread(new Runnable() {
                        public void run() {
                            if (ZKSignInActivity.this.mCameraView != null)
                                ZKSignInActivity.this.mCameraView.stopPreview();
                            if (ZKSignInActivity.this.mTextToSpeech != null)
                                ZKSignInActivity.this.mTextToSpeech.shutdown();
                            ZKSettingActivity.actionStart(ZKSignInActivity.this);
                            ZKSignInActivity.this.finish();
                        }
                    });
                }
                if (System.currentTimeMillis() - this.mMenuStaTime > this.mPrivilegeTime * 1000) {
                    this.mMenuState = false;
                    return;
                }
            }
        } else {
            SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.getDefault());
            if (this.mRepeatSignTime > 0) {
                if (this.mPageState) {
                    ZKMapData.putMeetCode(String.valueOf(this.mMeetInfo.getCode()));
                    if (this.mDao.getState(this.mMeetInfo.getCode(), localUserInfo.getUser_PIN()))
                        paramFaceSearchResult = (String) ZKMapData.MEET_MAP.get(localUserInfo.getUser_PIN());
                    else
                        paramFaceSearchResult = (String) ZKMapData.ATT_MAP.get(localUserInfo.getUser_PIN());
                } else {
                    paramFaceSearchResult = (String) ZKMapData.ATT_MAP.get(localUserInfo.getUser_PIN());
                }
                if ((paramFaceSearchResult != null) && (!paramFaceSearchResult.equals(""))) {
                    try {
                        Date localDate = new Date();
                        paramFaceSearchResult = new Date(localSimpleDateFormat.parse(paramFaceSearchResult).getTime() + this.mRepeatSignTime * 1000);
                        if (localDate.getTime() <= paramFaceSearchResult.getTime())
                            return;
                        if (this.MaxAttLogCount <= this.mDao.getAttLogCount()) {
                            if (this.mLoopDeleteLog > 0) {
                                this.mDao.deleteAttLog(this.mLoopDeleteLog);
                                addAttLog(localUserInfo, localSimpleDateFormat, this.mPageState);
                                return;
                            }
                            ZKToast.showToast(this, 2131624174);
                            return;
                        }
                        addAttLog(localUserInfo, localSimpleDateFormat, this.mPageState);
                        return;
                    } catch (ParseException paramFaceSearchResult) {
                        paramFaceSearchResult.printStackTrace();
                        return;
                    }
                } else {
                    if (this.MaxAttLogCount <= this.mDao.getAttLogCount()) {
                        if (this.mLoopDeleteLog > 0) {
                            this.mDao.deleteAttLog(this.mLoopDeleteLog);
                            addAttLog(localUserInfo, localSimpleDateFormat, this.mPageState);
                            return;
                        }
                        ZKToast.showToast(this, 2131624174);
                        return;
                    }
                    addAttLog(localUserInfo, localSimpleDateFormat, this.mPageState);
                    return;
                }
            } else {
                if (this.MaxAttLogCount <= this.mDao.getAttLogCount()) {
                    if (this.mLoopDeleteLog > 0) {
                        this.mDao.deleteAttLog(this.mLoopDeleteLog);
                        addAttLog(localUserInfo, localSimpleDateFormat, this.mPageState);
                        return;
                    }
                    ZKToast.showToast(this, 2131624174);
                    return;
                }
                addAttLog(localUserInfo, localSimpleDateFormat, this.mPageState);
            }
        }
    }

    public boolean onFindFace() {
        this.mADStaTime = System.currentTimeMillis();
        Object localObject = getFragmentManager();
        ZKPhotoADFragment localZKPhotoADFragment = (ZKPhotoADFragment) ((FragmentManager) localObject).findFragmentByTag(ZKPhotoADFragment.TAG);
        if (localZKPhotoADFragment != null) {
            runOnUiThread(new Runnable(localZKPhotoADFragment) {
                public void run() {
                    ZKSignInActivity.this.closeAD(this.val$photoFragment);
                }
            });
            return true;
        }
        localObject = (ZKVideoADFragment) ((FragmentManager) localObject).findFragmentByTag(ZKVideoADFragment.TAG);
        if (localObject != null) {
            runOnUiThread(new Runnable((ZKVideoADFragment) localObject) {
                public void run() {
                    ZKSignInActivity.this.closeAD(this.val$videoFragment);
                }
            });
            return true;
        }
        return false;
    }

    public void onInitFailed() {
        this.progressDialog.setTitle("人脸算法初始化失败");
        new Handler().postDelayed(new Runnable() {
                                      public void run() {
                                      }
                                  }
                , 1000L);
        this.progressDialog.dismiss();
    }

    public void onSdkInitSucceed() {
        new AsyncTask() {
            protected Object doInBackground(Object[] paramArrayOfObject) {
                ZKSignInActivity.this.reloadBioData();
                return null;
            }

            protected void onPostExecute(Object paramObject) {
                super.onPostExecute(paramObject);
                ZKSignInActivity.this.progressDialog.dismiss();
            }

            protected void onPreExecute() {
                super.onPreExecute();
            }
        }
                .execute(new Object[0]);
    }

    /**
     * 点击菜单按钮
     *
     * @param paramView
     */
    @OnClick({2131296611})
    public void onViewClicked(View paramView) {
        if (paramView.getId() != 2131296611)
            return;
        if (this.mDao.query14User() <= 0) {     // 查询是否是管理员
            ZKSettingActivity.actionStart(this);
            finish();
            return;
        }
        this.mMenuState = true;
        this.mMenuStaTime = System.currentTimeMillis();
        ZKToast.showToast(this, 2131624005);
    }

    private class TimerRun extends Thread {
        private TimerRun() {
        }

        public void run() {
            monitorenter;
            try {
                while (!ZKSignInActivity.this.mThreadState) {
                    if ((ZKSignInActivity.this.mFragPhotoAd == null) && (ZKSignInActivity.this.mFragVideoAd == null)) {
                        if (ZKSignInActivity.this.mADTime == 0)
                            return;
                        if ((ZKSignInActivity.this.mADOnOff) && (System.currentTimeMillis() - ZKSignInActivity.this.mADStaTime > ZKSignInActivity.this.mADTime * 1000))
                            ZKSignInActivity.this.runOnUiThread(new Runnable() {
                                public void run() {
                                    ZKSignInActivity.this.showAD();
                                }
                            });
                    }
                    try {
                        Thread.sleep(100L);
                    } catch (InterruptedException localInterruptedException) {
                        localInterruptedException.printStackTrace();
                    }
                }
                return;
            } finally {
                monitorexit;
            }
            throw localObject;
        }
    }
}
